// coding: utf-8
// @Author : lryself
// @Date : 2020/11/4 10:44
// @Software: GoLand

package main

func main() {
	
}
func insert(intervals [][]int, newInterval []int) [][]int {
	n:=len(intervals)
	if n==0{
		return [][]int{newInterval}
	}
	result := [][]int{}
	var index int
	for ;index<n;index++{
		if newInterval[0]>intervals[index][1]{
			result=append(result, intervals[index])
		}else {
			break
		}
	}
	for ;index<n;index++{
		if intervals[index][0]<=newInterval[1]{
			newInterval[0]=min(newInterval[0], intervals[index][0])
			newInterval[1]=max(newInterval[1], intervals[index][1])
		}else{
			break
		}
	}
	result=append(result, newInterval)
	return append(result, intervals[index:]...)
}
func max(a int,b int) int {
	if b>a{
		return b
	}
	return a
}
func min(a int ,b int) int {
	if a<b{
		return a
	}
	return b
}